<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="javax.servlet.RequestDispatcher" %>
<%@ page import="javax.jdo.Query" %>
<%@ page import="com.appspot.yozmcup.DO.PMF" %>
<%@ page import="com.appspot.yozmcup.DO.Winner" %>
<%@ page import="com.appspot.yozmcup.DO.User" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% 
	User user = null;
	if(session.getAttribute("user") != null){
		user = (User) session.getAttribute("user");
	}
%>
<!doctype html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>YOZM CUP</title>
	<link type="text/css" rel="stylesheet" href="/css/common.css" />
	<script type="text/javascript" src="/js/jigu.min.js"></script>
</head>
<body>
<%
	if(user != null){
%>
	<a class="etc_link" href="/Logout">Logout</a>
	<br /><br />
	<a class="title" href="http://yozm.daum.net/<%= user.getUrlName() %>" target="_blank"><%= user.getNickname() %></a> 님 안녕하세요! 게임하기 버튼으로 요즘컵을 즐겨보세요. &nbsp;&nbsp;&nbsp;
<%
	}
%>
	<br /><br />
	<p class="align_c msg">요즘컵은 요즘 친구 혹은 요즘컵 우승자들을 대상으로 이상형 대결을 하는 서비스입니다.</p>
	<div id="wrap">
		<p>
<%
	if(user != null) {
%>
			<input id="gameBtn" class="button_p10" type="button" value="게임하기" tabindex="13" />
<%
	} else {
%>
			<input id="loginBtn" class="button_p10" type="button" value="다음 로그인" tabindex="13" />
<%
	}
%>
		</p>
	</div>
	<br /><br />
	
	<h3>WINNER LIST</h3>
	<ul class="winner_ul">
	<%
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Query query = pm.newQuery(Winner.class);
	    query.setOrdering("cnt desc");
	    query.setRange("0, 100");
	    
	    
	    try {
	        List<Winner> results = (List<Winner>) query.execute();
	        if (!results.isEmpty()) {
	            for (Winner winner : results) {
	            	int cnt = winner.getCnt();
	    			String urlName = winner.getUrlName();
	    			String nickname = winner.getNickname();
	    			String imgUrl = winner.getProfileBigImgUrl();
	    			if(!"".equals(imgUrl)){
%>
		<li class="winner_li"><a href="http://yozm.daum.net/<%= urlName %>" title="<%= cnt %>회 우승!! <%= nickname %>" target="_blank"><img src="<%= imgUrl %>" width="100" height="100" alt="" /></a></li>
<%
					}
	            }
	        }
	    } finally {
	        query.closeAll();
	    }
	%>
	</ul>
	
	<script type="text/javascript">
	(function(){
		function playGame(){
			location.href = "/member.jsp";
		}
		
		function doLogin(){
			location.href = "/Login";
		}
		
		if($("loginBtn")) daum.Event.addEvent($("loginBtn"), "click", doLogin);
		if($("gameBtn")) daum.Event.addEvent($("gameBtn"), "click", playGame);
	})();
	</script>
</body>
</html>
